package com.bocai.kelalacar.ui.car.set.ada;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.bocai.kelalacar.R;
import com.bocai.kelalacar.bean.TravelInformationBean;
import com.bocai.kelalacar.widget.RoundedImageView;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuanfei on 2017/7/10.
 */

public class CarPhotoAda extends BaseAdapter {

    private ArrayList<TravelInformationBean.InfomationBean.Imagebean> list;
    private Context mContext;

    public CarPhotoAda(Context mContext,ArrayList<TravelInformationBean.InfomationBean.Imagebean> list){
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_car_photo, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(list.get(position).getMediumThumbnail()).into(viewHolder.ivPhoto);
        return convertView;
    }
    static class ViewHolder {
        @BindView(R.id.iv_photo)
        RoundedImageView ivPhoto;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    public void setPhotos(ArrayList<TravelInformationBean.InfomationBean.Imagebean> photos){
        this.list = photos;
        notifyDataSetChanged();
    }
}
